package com.module.base.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;

public class StringUtils {

    public static String formatPrice(double price) {
        BigDecimal bigDecimal = new BigDecimal(String.valueOf(price));
        return formatPrice(bigDecimal);
    }

    public static String formatPrice(float price) {
        BigDecimal bigDecimal = new BigDecimal(String.valueOf(price));
        return formatPrice(bigDecimal);
    }

    public static String formatPrice(String price) {
        BigDecimal bigDecimal = new BigDecimal(price);
        return formatPrice(bigDecimal);
    }

    public static String formatPrice(BigDecimal price) {
        return price.setScale(2, BigDecimal.ROUND_DOWN).stripTrailingZeros().toPlainString();
    }

    public static String formatNumber(double number) {
        DecimalFormat df = new DecimalFormat("#.##");
        String str;
        if (number >= 10000) {
            str = df.format(number / 10000) + "w";
        } else {
            str = df.format(number);
        }
        return str;
    }

    public static String formatNumber(float number) {
        return formatNumber(Double.parseDouble(String.valueOf(number)));
    }

    public static String formatNumber(int number) {
        return formatNumber(Double.parseDouble(String.valueOf(number)));
    }



    public static String formatFloorNumber(double number) {
        DecimalFormat df = new DecimalFormat("#.##");
        df.setRoundingMode(RoundingMode.FLOOR);
        String str;
        if (number >= 10000) {
            str = df.format(number / 10000) + "w";
        } else {
            str = df.format(number);
        }
        return str;
    }

    public static String formatFloorNumber(float number) {
        return formatFloorNumber(Double.parseDouble(String.valueOf(number)));
    }

    public static String formatFloorNumber(int number) {
        return formatFloorNumber(Double.parseDouble(String.valueOf(number)));
    }
}
